package com.hbun.cxcy.controller;


import com.hbun.cxcy.common.utils.PageUtils;
import com.hbun.cxcy.common.utils.R;
import com.hbun.cxcy.entity.Achievement;
import com.hbun.cxcy.service.AchievementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mahaunyu
 * @since 2022-01-24
 */
@CrossOrigin
@RestController
@RequestMapping("/cxcy/achievement")
public class AchievementController {
    @Autowired
    private AchievementService achievementsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("cxcyweb:achievements:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = achievementsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("cxcyweb:achievements:info")
    public R info(@PathVariable("id") Long id){
        Achievement achievements = achievementsService.getById(id);

        return R.ok().put("achievements", achievements);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Achievement achievements){
        System.out.println(achievements);
        achievementsService.saveWithCustom(achievements);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody Achievement achievements){
        achievementsService.updateByIdWithCustom(achievements);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("cxcyweb:achievements:delete")
    public R delete(@RequestBody Long[] ids){
        achievementsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}

